﻿using System;
using System.Collections.Generic;
using System.Reflection;

namespace IMDBApi.Contracts
{
    /// <summary>
    /// A class which provides all the functions to interact with the search feature of the IMDb iPhone API.
    /// </summary>
    public class IMDBSearch : IMDBBase
    {
        #region Constructor

        public IMDBSearch() : base() { }

        #endregion

        #region Public

        /// <summary>
        /// Makes the search request and returns the result
        /// </summary>
        /// <param name="searchterm">Search term for which should be searched.</param>
        /// <returns>Returns the search results as a JSON formatted string.</returns>
        public string GetSearchResults(string searchterm)
        {
            if (searchterm == string.Empty)
            {
                throw new Exception(MethodInfo.GetCurrentMethod().Name + ": A searchterm is required.");
            }
            else
            {
                Dictionary<string, string> q = new Dictionary<string, string>() { { "q", Uri.EscapeUriString(searchterm) } };
                return this.MakeRequest("/find", q);
            }
        }

        #endregion
    }
}